package com.cloud.template.luna.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Hystrix熔断器示例
 * Created by Viole on 2017/12/29.
 */
@Controller
@RequestMapping("hello")
public class HystrixTemplate {

    //Hystrix熔断器示例
    @RequestMapping("object")
    @ResponseBody
    @HystrixCommand(fallbackMethod = "helloObjectFallBack",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "400"),//指定多久超时，单位毫秒。超时进fallback
            @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),//判断熔断的最少请求数，默认是10；只有在一个统计窗口内处理的请求数量达到这个阈值，才会进行熔断与否的判断
            @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "10"),//判断熔断的阈值，默认值50，表示在一个统计窗口内有50%的请求处理失败，会触发熔断
    })
    public String helloObject(String object){
        return "Hello "+object+"!";
    }

    public String helloObjectFallBack(String object){
        return "helloObjectFallBack!";
    }

}
